chrome.tabs.getSelected(null, function (tab) {
	$('#code').qrcode(tab.url);
});

function gen() {
	$('#code').html(""); // 清除代码
	$('#code').qrcode(toUtf8($("#text").val()));
};

$('#btn').on('click', function(){gen();});

function toUtf8(str) {
    var rs = '';
        for(var i of str) {
            var code = i.codePointAt(0);
                if(code < 128) {
                    rs += i;
                } else if(code > 127 && code < 2048) {
                    rs += String.fromCharCode((code >> 6) | 192, (code & 63) | 128);
                } else if(code > 2047 && code < 65536) {
                    rs += String.fromCharCode((code >> 12) | 224, ((code >> 6) & 63) | 128, (code & 63) | 128);
                } else if(code > 65536 && code < 1114112) {
                    rs += String.fromCharCode((code >> 18) | 240, ((code >> 12) & 63) | 128, ((code >> 6) & 63) | 128, (code & 63) | 128);
            }
        }
        return rs;
}


	
